exports.install = function (Vue, options) {
  /**
   * 判断当前是否有此权限
   * 
  */
  Vue.prototype.isauth = function (authStr) {
    let authArr = JSON.parse(sessionStorage.getItem('permissions'))
    return authArr.includes(authStr);
  };
  /**
   * 获取用户类型描述
   */
  Vue.prototype.getUserTypeName = function (userType) {
    switch (userType) {
      case 1:
        return "系统管理员"
      case 50:
        return "代理商"
      case 100:
        return "学校用户"
      default:
        return "未知";
    }
  }
  /**
  * 检查是否是系统管理员
  */
  Vue.prototype.isSysAdmin = function (userType) {
    if (userType == 1) {
      return true;
    }

    return false;
  }

  /**
  * 检查是否是代理商
  */
  Vue.prototype.isAgent = function (userType) {
    if (userType == 50) {
      return true;
    }

    return false;
  }

  /**
  * 检查是否是单位用户
  */
  Vue.prototype.isUnitUser = function (userType) {
    if (userType == 100) {
      return true;
    }

    return false;
  }


  /**
   * 获取单位类型描述
   */
  Vue.prototype.getUnitTypeName = function (unitType) {
    switch (Number(unitType)) {
      case 1:
        return "系统单位";
      case 50:
        return "代理商";
      case 100:
        return "学校";
      default:
        return "未知";
    }
  }

  /**
* 检查是否是系统单位
*/
  Vue.prototype.isSystemUnit = function (unitType) {
    if (unitType == 1) {
      return true;
    }

    return false;
  }

  /**
* 检查是否是代理单位
*/
  Vue.prototype.isAgentUnit = function (unitType) {
    if (unitType == 50) {
      return true;
    }

    return false;
  }

  /**
* 检查是否是普通单位
*/
  Vue.prototype.isOrdinaryUnit = function (unitType) {
    if (unitType == 100) {
      return true;
    }

    return false;
  }

  /**
   * 用户类型
   */
  Vue.filter('userTypeFilter', function (userType) {
    switch (userType) {
      case 1:
        return "系统管理员"
      case 50:
        return "代理商管理员"
      case 100:
        return "单位用户"
      default:
        return "未知";
    }
  })

  /**
 * 交易状态过滤器
 */
  Vue.filter('isSuccesstype', function (isSuccess) {
    if (isSuccess == 0) {
      return "非确定交易";
    }
    if (isSuccess == 1) {
      return "成功";
    }
    if (isSuccess == 2) {
      return "非确定退款";
    }
    if (isSuccess == 3) {
      return "正常退款";
    }
    if (isSuccess == 5) {
      return "流水号已过期";
    }
    if (isSuccess == 6) {
      return "非确定圈存";
    }
  })
  /**
   * 交易类型过滤器
   */
  Vue.filter('filterchargingType', function (chargingType) {
    if (chargingType == '0') {
      return '卡务中心充值'
    }
    if (chargingType == '193') {
      return '充值机充值'
    }
    if (chargingType == '191') {
      return '平台无卡充值'
    }
    if (chargingType == '192') {
      return '支付宝充值'
    }
    if (chargingType == '196') {
      return '微信充值'
    }
    if (chargingType == '195') {
      return '第三方充值'
    }
    if (chargingType == '1') {
      return '消费'
    }
    if (chargingType == '2') {
      return '卡务中心减款'
    }
    if (chargingType == '18') {
      return '平台无卡减款'
    }
    if (chargingType == '33') {
      return '圈存'
    }
    if (chargingType == '3') {
      return '退卡'
    }
    if (chargingType == '4') {
      return '损益'
    }
    if (chargingType == '5') {
      return '补冻'
    }
    if (chargingType == '6') {
      return '坏账'
    }
    if (chargingType == '7') {
      return '退注销卡'
    }
    if (chargingType == '8') {
      return '消费修正'
    }
    if (chargingType == '9') {
      return '订餐'
    }
    if (chargingType == '11') {
      return '补贴'
    }
    if (chargingType == '12') {
      return '补贴消费'
    }
    if (chargingType == '15') {
      return '水控消费'
    }
    if (chargingType == '16') {
      return '对账'
    }
    if (chargingType == '17') {
      return '对账替换'
    }

    if (chargingType == '19') {
      return '合并'
    }
    if (chargingType == '20') {
      return '无卡消费'
    }
    if (chargingType == '21') {
      return '无卡消费结束'
    }
    if (chargingType == '22') {
      return '在线充值'
    }
    if (chargingType == '25') {
      return '计次消费'
    }
    if (chargingType == '30') {
      return '发卡预存款'
    }
    if (chargingType == '200') {
      return '补贴水量'
    }
  })
  /**
  * 交易类型函数
  */
  Vue.prototype.filterchargingType = function (chargingType) {
    if (chargingType == '0') {
      return '卡务中心充值'
    }
    if (chargingType == '193') {
      return '充值机充值'
    }
    if (chargingType == '191') {
      return '平台无卡充值'
    }
    if (chargingType == '192') {
      return '支付宝充值'
    }
    if (chargingType == '196') {
      return '微信充值'
    }
    if (chargingType == '195') {
      return '第三方充值'
    }
    if (chargingType == '1') {
      return '消费'
    }
    if (chargingType == '2') {
      return '卡务中心减款'
    }
    if (chargingType == '18') {
      return '平台无卡减款'
    }
    if (chargingType == '33') {
      return '圈存'
    }
    if (chargingType == '3') {
      return '退卡'
    }
    if (chargingType == '4') {
      return '损益'
    }
    if (chargingType == '5') {
      return '补冻'
    }
    if (chargingType == '6') {
      return '坏账'
    }
    if (chargingType == '7') {
      return '退注销卡'
    }
    if (chargingType == '9') {
      return '订餐'
    }
    if (chargingType == '11') {
      return '补贴'
    }
    if (chargingType == '12') {
      return '补贴消费'
    }
    if (chargingType == '15') {
      return '水控消费'
    }
    if (chargingType == '16') {
      return '对账'
    }
    if (chargingType == '17') {
      return '对账替换'
    }
    if (chargingType == '19') {
      return '合并'
    }
    if (chargingType == '20') {
      return '无卡消费'
    }
    if (chargingType == '21') {
      return '无卡消费结束'
    }
    if (chargingType == '25') {
      return '计次消费'
    }
    if (chargingType == '30') {
      return '发卡预存款'
    }
    if (chargingType == '200') {
      return '补贴水量'
    }
  }


  /**
 * 门锁类型
 */
  Vue.filter('cardtypesoptionType', function (val) {
    val = Number(val);
    switch (val) {
      case 1:
        return "正常刷卡";
        break;
      case 2:
        return "非法卡";
        break;
      case 3:
        return "钥匙开门";
        break;
      case 4:
        return "远程开门";
        break;
      case 5:
        return "远程常开";
        break;
      case 6:
        return "远程闭门";
        break;
      case 7:
        return "反锁";
        break;
      case 8:
        return "解除反锁";
        break;
      case 10:
        return "假锁";
        break;
      case 11:
        return "卡格式错误";
        break;
      case 12:
        return "脱机授权记录";
        break;
      case 13:
        return "名单卡记录";
        break;
      case 14:
        return "时效密码开门";
        break;
      case 15:
        return "临时密码开门";
        break;
      case 21:
        return "密码开门";
        break;
      case 22:
        return "超级密码开门";
        break;
      case 23:
        return "胁迫密码开门";
        break;
      case 25:
        return "电量数据";
        break;
      case 34:
        return "远程关门";
        break;
      case 35:
        return "远程取消常开";
        break;
      case 36:
        return "远程取消封门";
        break;
      case 41:
        return "用户指纹认证开门";
        break;
      case 42:
        return "管理员指纹认证开门";
        break;
      case 45:
        return "增加指纹";
        break;
      case 252:
        return "配置卡";
        break;
      case 253:
        return "授权卡";
        break;
      default:
        return "";
        break;
    }

  })
  /**
  * 金额化元过滤器,分转元
  */
  Vue.filter('amountyuan', function (amount) {
    if(amount == null){
      return ''
    }
    var num = amount;
    if (num == 0) {
      return num
    }
    num = amount * 0.01;
    num += '';
    var reg = num.indexOf('.') > -1 ? /(\d{1,3})(?=(?:\d{3})+\.)/g : /(\d{1,3})(?=(?:\d{3})+$)/g;
    num = num.replace(reg, '$1');
    // num = toDecimal2(num)
    var f = parseFloat(num)
    if (isNaN(f)) {
      return 0;
    }
    var f = Math.round(num * 100) / 100;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
      rs = s.length;
      s += '.';
    }
    while (s.length <= rs + 2) {
      s += '0';
    }
    num = s
    return num
  })
  /**
  * 金额化元过滤器,角转元
  */
  Vue.filter('amountjiao', function (amount) {
    var num = amount;
    if (num == 0) {
      return num
    }
    num = amount * 0.01;
    num += '';
    var reg = num.indexOf('.') > -1 ? /(\d{1,3})(?=(?:\d{3})+\.)/g : /(\d{1,3})(?=(?:\d{3})+$)/g;
    num = num.replace(reg, '$1');
    // num = toDecimal2(num)
    var f = parseFloat(num)
    if (isNaN(f)) {
      return false;
    }
    var f = Math.round(num * 100) / 10;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
      rs = s.length;
      s += '.';
    }
    while (s.length <= rs + 2) {
      s += '0';
    }
    num = s
    return num
  })
  /**
   * 时间换算过滤器
   */
  Vue.filter('timeconversion', function (time) {
    if (time) {
      let timenum = time % 60
      if (timenum >= 30) {
        time = parseInt(time / 60)
        time = time + 1
      } else {
        time = parseInt(time / 60)
      }
    }
    return time
  })
  /**
* 度数转化
*/
  Vue.filter('amountKWH', function (amount) {
    var num = amount;
    if (num == 0) {
      return num
    }
    num = amount * 0.001;
    num += '';
    var reg = num.indexOf('.') > -1 ? /(\d{1,3})(?=(?:\d{3})+\.)/g : /(\d{1,3})(?=(?:\d{3})+$)/g;
    num = num.replace(reg, '$1');
    // num = toDecimal2(num)
    var f = parseFloat(num)
    if (isNaN(f)) {
      return false;
    }
    var f = Math.round(num * 100) / 1000;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
      rs = s.length;
      s += '.';
    }
    while (s.length <= rs + 2) {
      s += '0';
    }
    num = s
    return num
  })

  /**
   * 金额化元函数,分化元
   */
  Vue.prototype.amountyua = function (amount) {
    var num = amount;
    // console.log(num)
    if (num == 0) {
      return num
    }
    num = amount * 0.01;
    num += '';
    var reg = num.indexOf('.') > -1 ? /(\d{1,3})(?=(?:\d{3})+\.)/g : /(\d{1,3})(?=(?:\d{3})+$)/g;
    num = num.replace(reg, '$1');
    // num = toDecimal2(num)
    var f = parseFloat(num)
    if (isNaN(f)) {
      return false;
    }
    var f = Math.round(num * 100) / 100;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
      rs = s.length;
      s += '.';
    }
    while (s.length <= rs + 2) {
      s += '0';
    }
    num = s
    return num
  }
  /**
 * 金额化元函数角化元
 */
  Vue.prototype.amountjia = function (amount) {
    var num = amount;
    num = amount * 0.01;
    num += '';
    var reg = num.indexOf('.') > -1 ? /(\d{1,3})(?=(?:\d{3})+\.)/g : /(\d{1,3})(?=(?:\d{3})+$)/g;
    num = num.replace(reg, '$1');
    // num = toDecimal2(num)
    var f = parseFloat(num)
    if (isNaN(f)) {
      return false;
    }
    var f = Math.round(num * 100) / 10;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
      rs = s.length;
      s += '.';
    }
    while (s.length <= rs + 2) {
      s += '0';
    }
    num = s
    return num
  }
  /**
 * 餐别限制最大金额
 */
  Vue.prototype.amountrestriction = function (amount) {
    if (amount < 0 || amount > 650) {
      this.$message({
        message: '金额数据格式不正确范围在0~650',
        type: 'warning'
      });
      amount = 0
    }
    return amount
  }
  /**
   * 时间换算
   */
  Vue.prototype.timeconversion = function (time) {
    if (time) {
      let timenum = time % 60
      if (timenum >= 30) {
        time = parseInt(time / 60)
        time = time + 1
      } else {
        time = parseInt(time / 60)
      }
    }
    return time
  }
  /**
* 电量转为度
*/
  Vue.prototype.amountkwh = function (amount) {
    var num = amount;
    if (num == 0) {
      return num
    }
    num = amount * 0.001;
    num += '';
    var reg = num.indexOf('.') > -1 ? /(\d{1,3})(?=(?:\d{3})+\.)/g : /(\d{1,3})(?=(?:\d{3})+$)/g;
    num = num.replace(reg, '$1');
    // num = toDecimal2(num)
    var f = parseFloat(num)
    if (isNaN(f)) {
      return false;
    }
    var f = Math.round(num * 100) / 1000;
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
      rs = s.length;
      s += '.';
    }
    while (s.length <= rs + 2) {
      s += '0';
    }
    num = s
    return num
  }

  /**
* 设备型号
*/
  Vue.filter('terminalTypeOption', function (val) {
    let obj = {
      "1": "消费机",
      "2": "充值机",
      "6": "水控",
      "21": "门禁",
      "22": "电子门锁",
      "23": "多门门禁",
      "24": "空调",
      "25": "归宿终端",
      "26": "无人售货机",
      "27": "直饮水机",
      "28": "电吹风",
      "29": "发卡机",
      "30": "中继",
      "31": "电控",
      "32": "公话",
      "255": "控制器"
    }
    return obj[val];
  })
  /**
* 设备型号
*/
  Vue.filter('terminalModelOption', function (val) {
    let obj = {
      '53': 'S810CW',
      '55': 'S910CW',
      '57': 'S862CW',
      '58': 'S962CW',
      '61': 'S962CW_CZ',
      '32': 'F300CW',
      '50': 'F500CW',
      '51': 'F600CW',
      '56': 'F562CW',
      '59': 'F662CW',
      '2': 'K700CW',
      '3': 'K700CT',
      '15': 'A1422T',
      '70': 'A1262T',
      '43': 'EL200CW',
      '45': 'EL150CW',
      '46': 'EL150C-A',
      '47': 'EL150C-B',
      '48': 'EL300CW',
      '125': 'KongTiao',
      '130': 'GuiSuZhongDuan',
      '135': 'ShouHuoJi',
      '145': 'DianChuiFeng',
      '88': 'CM061CW',
      '110': 'WE1600',
      '111': 'WE1611',
      '112': 'WE1620',
      '71': 'EC100',
      '150': 'VOIP',
      '91': 'MC3611',
      '92': 'MC3612',
      '93': 'CT1601',
      '95': 'CT1612',
      '96': 'MC3622',
      '97': 'CT1632',
    }
    if (obj[val]) {
      return obj[val];
    } else {
      return '未知型号';
    }
  })

  /**
  * 交易状态
  */
  Vue.filter('fileterrechargeState', function (rechargeState) {
    if (rechargeState === 0) {
      return (rechargeState = "未下发");
    } else if (rechargeState === 1) {
      return (rechargeState = "执行成功");
    } else if (rechargeState === 2) {
      return (rechargeState = "执行失败");
    } else if (rechargeState === 3) {
      return (rechargeState = "已合并");
    }
  })
  /**
  * 交易类型
  */
  Vue.filter('fileteradjustType', function (val) {
    let str = String(val);
    let obj = { 1: "充值", 2: "对账", 3: "对账替换", 4: "代扣", 5: "合并" };
    return obj[val];
  })

}

